<!-- 活动地图页 -->
<template>
  <div class="activity_wrapper">
    <!--地图-->
    <div id="tdmap"></div>
  </div>
</template>

<script>
var _self, map, geocode;
import mapjson from "./map.json";
export default {
  data() {
    // 118.51983351374406,37.8857043651381
    return {
      originLocate: {
        x: 118.51983351374406,
        y: 37.8857043651381
      },
      newLocate: {
        x: 118.51983351374406,
        y: 37.8857043651381
      },
      // 底部
      active: 0,
      tabbarIcons: [
        {
          normal: require("../../assets/home/bottom_icon (2).png"),
          active: require("../../assets/home/bottom_icon (6).png")
        },
        {
          normal: require("../../assets/home/bottom_icon (5).png"),
          active: require("../../assets/home/bottom_icon (1).png")
        },
        {
          normal: require("../../assets/home/bottom_icon (3).png"),
          active: require("../../assets/home/bottom_icon (7).png")
        },
        {
          normal: require("../../assets/home/bottom_icon (4).png"),
          active: require("../../assets/home/bottom_icon (8).png")
        }
      ],
      Searchkey: window.Searchkey || "", //搜索关键字
      // 下拉框选项
      region: [
        {
          text: "活动区域",
          value: ""
        }
      ], //活动区域
      types: [
        {
          text: "活动类型",
          value: ""
        }
      ], // 活动类型
      states: [
        {
          text: "活动状态",
          value: ""
        }
      ], // 活动状态
      dataAreaCode: "", //活动区域
      activityType: "", //活动类型
      activityStatus: "", //活动状态
      value1: "", //活动区域
      value2: "", //活动类型
      value3: "", //活动状态
      pageIndex: 1,
      pageSize: 80,
      totalCount: 0
    };
  },
  components: {},
  created() {
    _self = this;
    this.$nextTick(() => {
      this.loadMap();
    });
  },
  methods: {
    change() {
      window.Searchkey = this.Searchkey;
    },
    setMapMarker(r) {
      map = new T.Map("tdmap");
      map.centerAndZoom(
        new T.LngLat(_self.originLocate.x, _self.originLocate.y),
        16
      );

      console.log('r', r);
      r.list.forEach(e => {
        let radou = Math.random().toFixed(2) * 0.01;
        console.log(radou);
        if (!e.x && !e.y) {
          e.x = 118.51686919088037 + radou;
          e.y = 37.88295348274101 + radou;
        }
      });
      this.addMarkers(r.list);
    },
    addMarkers(list) {
      let _self = this;
      map.clearOverLays();
      map.centerAndZoom(new T.LngLat(list[0].x, list[0].y), 15);
      list.forEach(e => {
        var marker = new T.Marker(new T.LngLat(e.x, e.y)); // 创建标注
        map.addOverLay(marker); // 将标注添加到地图中
        var label = new T.Label({
          text: "<b>" + e.title + "<b>",
          position: marker.getLngLat(),
          offset: new T.Point(-30, -60)
        });
        map.addOverLay(label);
        marker.addEventListener("click", function() {
          _self.$router.push({
            path: "/activityDetails",
            query: {
              DetailData: e
            }
          });
        });
      });
    },
    // 初始化地图
    loadMap() {
      map = new T.Map("tdmap");
      map.centerAndZoom(
        new T.LngLat(_self.originLocate.x, _self.originLocate.y),
        16
      );
    },
    onSearch() {
      this.GetList();
    },
    clickBtn() {
      this.$router.push({
        path: "/activity"
      });
    },
    //获取活动区域
    zoneAction() {
      this.post("community_activity/regiontype")
        .then(r => {
          // this.value1=  r.list[0].regionCode
          r.list.forEach(element => {
            if (this.region) {
              this.region.push({
                text: element.regionName,
                value: element.regionCode
              });
            } else {
              this.region.push({
                text: "活动区域",
                value: "0"
              });
            }
          });
        })
        .catch(err => {});
    },
    // 下拉框选项
    bara(a) {
      this.dataAreaCode = a;
      this.GetList();
    },
    barb(b) {
      this.activityType = b;
      this.GetList();
    },
    barc(c) {
      this.activityStatus = c;
      this.GetList();
    }
  }
};
</script>

<style lang="scss">
@import "~@/smobile.scss";
.activity_wrapper {
  background: #ffffff !important;
  #tdmap {
    position: fixed;
    top: 145px;
    left: 0;
    right: 0;
    bottom: 0;
  }
  .search_box {
    margin-top: 10px;
    .van-search--show-action {
      padding-right: 5px;
    }
    .van-search {
      padding: 0px 20px 0 20px;
      .van-cell {
        padding: 6px 8px 6px 0;
      }
    }
    .van-search__action {
      color: #1e9ff6;
      font-size: 16px;
    }
  }
  .NavigatBar {
    margin-top: 15px;
    .van-dropdown-menu {
      box-shadow: 0px 2px 0px #e6eeee;
    }
    .van-dropdown-item {
      top: 100px !important;
    }
  }
  .switchBtn {
    position: absolute;
    left: 0;
    bottom: 30%;
    display: flex;
    width: 40vw;
    height: 12vw;
    line-height: 12vw;
    span {
      width: 50%;
      text-align: center;
      color: #ffffff;
      font-size: 14px;
      background: rgba(0, 0, 0, 0.2);
    }
    .Selectle {
      background: #1699ee;
    }
  }
  .tabbarBox {
    .tabbarItem {
      justify-content: flex-end;
      margin-bottom: $sm-spacing-col-base;
      z-index: 2;
      .tabbarIcon {
        height: $sm-icon-px-lg !important;
      }
    }
  }
}
</style>
